<template>
  <el-dialog class="assign-role" title="分配角色" :visible="showRoleDialog" @close="closeRoleDialog" @open="open">
    <!-- 这里准备复选框 -->
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div style="text-align: right">
        <el-button type="primary" size="small">确定</el-button>
        <el-button size="small" @click="closeRoleDialog">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { getRoleList } from '@/api/settings'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    showRoleDialog: {
      type: Boolean,
      default: false
    },
    curId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      roleIds: [],
      list: []
    }
  },
  methods: {
    closeRoleDialog() {
      this.$emit('close-role-dialog', false)
    },
    async getRoleList() {
      const data = await getRoleList(1, 100)
      console.log(data)
      this.list = data.rows
    },
    open() {
      this.getRoleList()
    },
    async assignRole() {
      await assignRoles({ id: this.curId, roleIds: this.roleIds })
      this.closeRoleDialog()
    }
  }
}
</script>
<style lang="scss" scoped>
.assign-role {
  ::v-deep {
    .el-checkbox {
      font-size: 30px;
    }
  }
}
</style>
